#ifndef _ST7735_H_
#define _ST7735_H_

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_lcd_panel_interface.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lcd_panel_commands.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "esp_check.h"
#include "driver/spi_common.h"

#include "lvgl.h"

typedef struct
{
    esp_lcd_panel_t base;
    esp_lcd_panel_io_handle_t io;
    int reset_gpio_num;
    bool reset_level;
    int x_gap;
    int y_gap;
    unsigned int bits_per_pixel;
    uint8_t madctl_val; // save current value of LCD_CMD_MADCTL register
    uint8_t colmod_cal; // save surrent value of LCD_CMD_COLMOD register
} st7735_panel_t;

#pragma once

#define LCD_PIXEL_CLOCK_HZ (26.6 * 1000 * 1000)

#define SPI_NUM_PORT SPI2_HOST
#define PIN_NUM_SCLK 7
#define PIN_NUM_MOSI 6

#define PIN_NUM_CS 4
#define PIN_NUM_DC 5
#define PIN_NUM_RST 48
#define PIN_NUM_BK_LIGHT 15


// #define PIN_NUM_SCLK 12
// #define PIN_NUM_MOSI 11

// #define PIN_NUM_CS 10
// #define PIN_NUM_DC 13
// #define PIN_NUM_RST 8
// #define PIN_NUM_BK_LIGHT 14

// // The pixel number in horizontal and vertical
// #define LCD_H_RES 128
// #define LCD_V_RES 128

#define LVGL_TICK_PERIOD_MS 2

void guiTask(void *pvParameter);


extern esp_err_t esp_lcd_new_panel_st7735(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel);
extern void st7735_init(void);
#endif
